var number = 10;
var startingPage;

//删除数据
function Delete_Data(inform_id) {
    var data = {
        "inform_id": inform_id,
        "inform_deleteState": 2
    };
    swal.fire({
        type: 'warning', // 弹框类型
        title: '确认', //标题
        text: "确认删除此数据", //显示内容
        confirmButtonColor: '#3085d6',// 确定按钮的 颜色
        confirmButtonText: '确定',// 确定按钮的 文字
        showCancelButton: true, // 是否显示取消按钮
        cancelButtonColor: '#d33', // 取消按钮的 颜色
        cancelButtonText: "取消", // 取消按钮的 文字
        focusCancel: true, // 是否聚焦 取消按钮
        reverseButtons: true  // 是否 反转 两个按钮的位置 默认是  左边 确定  右边 取消
    }).then(function (isConfirm) {
        if (isConfirm.value) {
            $.ajax({
                url: "updateInformByInformDeleteState",
                type: "POST",
                dataType: "json",
                contentType: 'application/json;charset=utf-8',
                data: JSON.stringify(data),
                async: false,
                success: function (data) {
                    if (data.code == 200) {
                        Swal.fire("提示", "删除数据成功", "success");
                    } else {
                        Swal.fire("提示", "删除数据失败", "error");
                    }
                }
            });
            loadWebList();
        } else {
            Swal.fire("提示", "已取消提交", "error");
        }
    })
}

//初始数据
function loadWebList() {
    startingPage = 0;
    var data = {
        "page": startingPage,
        "number": number
    };
    $.ajax({
        url: "findInformByInformList",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(data),
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            var code = ' ';
            if (data.code == 500) {
                Swal.fire("提示", "查询数据失败", "error");
            } else {
                for (var i = 0; i < data.inform_List.length; i++) {
                    code += "  <tr>\n" +
                        "                            <td>" + (i + 1) + "</td>\n" +
                        "                            <td><img style='width: 300px;height: 50px;' src='upload/" + data.inform_List[i].inform_image + "  '></td>\n" +
                        "                            <td>" + data.inform_List[i].inform_title + "</td>\n" +
                        "                            <td>" + data.inform_List[i].inform_volume + "</td>\n" +
                        "                            <td>" + data.inform_List[i].inform_Date + "</td>\n" +
                        "                            <td class=\"td-manage\">\n" +
                        "                                      <a onclick=\"Delete_Data(" + data.inform_List[i].inform_id + ",this)\" title=\"删除\" href=\"javascript:;\">\n" +
                        "                                        <i class=\"layui-icon\">&#xe640;</i>\n" +
                        "                                      </a>\n" +
                        "                            </td>\n" +
                        "                        </tr>"
                }
                $("#SellerData").html(code);
                $("#pageNumber").val(data.count);
                $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next()'>&gt;&gt;</a>");
            }
        }
    });
}

//上一页
function myProjectTable_previous() {
    startingPage = startingPage - 1;
    if (startingPage < 0) {
        startingPage = 0;
        Swal.fire("提示", "数据不存在", "warning");
    } else {
        var data = {
            "page": startingPage * number,
            "number": number
        };
        $.ajax({
            url: "findInformByInformList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {
                    Swal.fire("提示", "查询数据失败", "error");
                } else {
                    for (var i = 0; i < data.inform_List.length; i++) {
                        code += "  <tr>\n" +
                            "                            <td>" + (i + 1) + "</td>\n" +
                            "                            <td><img style='width: 300px;height: 50px;' src='upload/" + data.inform_List[i].inform_image + "  '></td>\n" +
                            "                            <td>" + data.inform_List[i].inform_title + "</td>\n" +
                            "                            <td>" + data.inform_List[i].inform_volume + "</td>\n" +
                            "                            <td>" + data.inform_List[i].inform_Date + "</td>\n" +
                            "                            <td class=\"td-manage\">\n" +
                            "                                      <a onclick=\"Delete_Data(" + data.inform_List[i].inform_id + ",this)\" title=\"删除\" href=\"javascript:;\">\n" +
                            "                                        <i class=\"layui-icon\">&#xe640;</i>\n" +
                            "                                      </a>\n" +
                            "                            </td>\n" +
                            "                        </tr>"
                    }
                    $("#SellerData").html(code);
                    $("#pageNumber").val(data.count);
                    $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next()'>&gt;&gt;</a>");
                }
            }
        });
    }
}

//下一页
function myProjectTable_next() {
    startingPage = startingPage + 1;
    var startingPageNumber = startingPage * number;
    var numberSum = $("#pageNumber").val();
    if (startingPageNumber > numberSum && (startingPageNumber - number) < numberSum) {
        startingPage = startingPage - 1;
        Swal.fire("提示", "数据浏览已到底", "warning");
    } else {
        var data = {
            "page": startingPageNumber,
            "number": number
        };
        $.ajax({
            url: "findInformByInformList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {
                    Swal.fire("提示", "查询数据失败", "error");
                } else {
                    for (var i = 0; i < data.inform_List.length; i++) {
                        code += "  <tr>\n" +
                            "                            <td>" + (i + 1) + "</td>\n" +
                            "                            <td><img style='width: 300px;height: 50px;' src='upload/" + data.inform_List[i].inform_image + "  '></td>\n" +
                            "                            <td>" + data.inform_List[i].inform_title + "</td>\n" +
                            "                            <td>" + data.inform_List[i].inform_volume + "</td>\n" +
                            "                            <td>" + data.inform_List[i].inform_Date + "</td>\n" +
                            "                            <td class=\"td-manage\">\n" +
                            "                                      <a onclick=\"Delete_Data(" + data.inform_List[i].inform_id + ",this)\" title=\"删除\" href=\"javascript:;\">\n" +
                            "                                        <i class=\"layui-icon\">&#xe640;</i>\n" +
                            "                                      </a>\n" +
                            "                            </td>\n" +
                            "                        </tr>"
                    }
                    $("#SellerData").html(code);
                    $("#pageNumber").val(data.count);
                    $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next()'>&gt;&gt;</a>");
                }
            }
        });
    }
}

//模糊初始数据
function loadWebList_1() {
    startingPage = 0;
    var searchName = $("#searchName").val();
    var data = {
        "page": startingPage,
        "number": number,
        "inform_title": searchName
    };
    $.ajax({
        url: "findInformByInformConcatList",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(data),
        contentType: 'application/json;charset=utf-8',
        success: function (data) {
            var code = ' ';
            if (data.code == 500) {
                Swal.fire("提示", "查询数据失败", "error");
            } else {
                for (var i = 0; i < data.inform_List.length; i++) {
                    code += "  <tr>\n" +
                        "                            <td>" + (i + 1) + "</td>\n" +
                        "                            <td><img style='width: 300px;height: 50px;' src='upload/" + data.inform_List[i].inform_image + "  '></td>\n" +
                        "                            <td>" + data.inform_List[i].inform_title + "</td>\n" +
                        "                            <td>" + data.inform_List[i].inform_volume + "</td>\n" +
                        "                            <td>" + data.inform_List[i].inform_Date + "</td>\n" +
                        "                            <td class=\"td-manage\">\n" +
                        "                                      <a onclick=\"Delete_Data(" + data.inform_List[i].inform_id + ",this)\" title=\"删除\" href=\"javascript:;\">\n" +
                        "                                        <i class=\"layui-icon\">&#xe640;</i>\n" +
                        "                                      </a>\n" +
                        "                            </td>\n" +
                        "                        </tr>"
                }
                $("#SellerData").html(code);
                $("#pageNumber").val(data.count);
                $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous_1()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next_1()'>&gt;&gt;</a>");
            }
        }
    });
}

//模糊初始数据上一页
function myProjectTable_previous_1() {
    startingPage = startingPage - 1;
    if (startingPage < 0) {
        startingPage = 0;
        Swal.fire("提示", "数据不存在", "warning");
    } else {
        var searchName = $("#searchName").val();
        var data = {
            "page": startingPage,
            "number": number,
            "inform_title": searchName
        };
        $.ajax({
            url: "findInformByInformConcatList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {
                    Swal.fire("提示", "查询数据失败", "error");
                } else {
                    for (var i = 0; i < data.inform_List.length; i++) {
                        code += "  <tr>\n" +
                            "                            <td>" + (i + 1) + "</td>\n" +
                            "                            <td><img style='width: 300px;height: 50px;' src='upload/" + data.inform_List[i].inform_image + "  '></td>\n" +
                            "                            <td>" + data.inform_List[i].inform_title + "</td>\n" +
                            "                            <td>" + data.inform_List[i].inform_volume + "</td>\n" +
                            "                            <td>" + data.inform_List[i].inform_Date + "</td>\n" +
                            "                            <td class=\"td-manage\">\n" +
                            "                                      <a onclick=\"Delete_Data(" + data.inform_List[i].inform_id + ",this)\" title=\"删除\" href=\"javascript:;\">\n" +
                            "                                        <i class=\"layui-icon\">&#xe640;</i>\n" +
                            "                                      </a>\n" +
                            "                            </td>\n" +
                            "                        </tr>"
                    }
                    $("#SellerData").html(code);
                    $("#pageNumber").val(data.count);
                    $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous_1()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next_1()'>&gt;&gt;</a>");
                }
            }
        });
    }
}

//模糊初始数据下一页
function myProjectTable_next_1() {
    startingPage = startingPage + 1;
    var startingPageNumber = startingPage * number;
    var numberSum = $("#pageNumber").val();
    if (startingPageNumber > numberSum && (startingPageNumber - number) < numberSum) {
        startingPage = startingPage - 1;
        Swal.fire("提示", "数据浏览已到底", "warning");
    } else {
        var searchName = $("#searchName").val();
        var data = {
            "page": startingPage,
            "number": number,
            "inform_title": searchName
        };
        $.ajax({
            url: "findInformByInformConcatList",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(data),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                var code = ' ';
                if (data.code == 500) {
                    Swal.fire("提示", "查询数据失败", "error");
                } else {
                    for (var i = 0; i < data.inform_List.length; i++) {
                        code += "  <tr>\n" +
                            "                            <td>" + (i + 1) + "</td>\n" +
                            "                            <td><img style='width: 300px;height: 50px;' src='upload/" + data.inform_List[i].inform_image + "  '></td>\n" +
                            "                            <td>" + data.inform_List[i].inform_title + "</td>\n" +
                            "                            <td>" + data.inform_List[i].inform_volume + "</td>\n" +
                            "                            <td>" + data.inform_List[i].inform_Date + "</td>\n" +
                            "                            <td class=\"td-manage\">\n" +
                            "                                      <a onclick=\"Delete_Data(" + data.inform_List[i].inform_id + ",this)\" title=\"删除\" href=\"javascript:;\">\n" +
                            "                                        <i class=\"layui-icon\">&#xe640;</i>\n" +
                            "                                      </a>\n" +
                            "                            </td>\n" +
                            "                        </tr>"
                    }
                    $("#SellerData").html(code);
                    $("#pageNumber").val(data.count);
                    $("#myProjectTable").html(" <a class=\"prev\"  onclick='myProjectTable_previous_1()'>&lt;&lt;</a> <span class=\"current\">" + (startingPage + 1) + "</span><a class=\"next\" onclick='myProjectTable_next_1()'>&gt;&gt;</a>");
                }
            }
        });
    }
}


$(function () {
    loadWebList();
});
